package com.chixing.controller;

import com.chixing.pojo.CustomerTokenDTO;
import com.chixing.utils.TokenUtil;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class WebSocketCouponProducer {
    @Autowired
    private AmqpTemplate rabbitTemplate;

    @PostMapping("CouponWebsocket")
    public String payCoupon(HttpServletRequest request){
        String token = request.getHeader("token");
        CustomerTokenDTO customerTokenDTO = TokenUtil.parseToken(token);
        Integer id = customerTokenDTO.getCustId();
        String userName = customerTokenDTO.getCustName();
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("userName",userName);
        rabbitTemplate.convertAndSend("webSocketCouponExchange","zhtCoupon",map);
        return "发送消息成功";
    }
}
